/**
 * 自定义函数
 * */

var apiDomain = '/api/h5/';
var pageSize = 10;


//显示前几个字符
function strPrefix(str, limit){
    if (str.length > limit) {
        return str.substring(0, limit) + '...';
    } else {
        return str;
    }
}


//显示后几个字符
function strSuffix(str, limit){
    if (str.length > limit) {
        return '...' + str.slice(- limit);
    } else {
        return str;
    }
}


//自定义弹窗
function msgPop(e){
    var cw = document.documentElement.clientWidth;
    var ch = document.documentElement.clientHeight;
    var msg = e.msg;
    var cwb = cw * 0.5; cwb = cwb>500 ? 500 : cwb;
    var h = '';
    h += '<div style="position: fixed; top: 0; left: 0; z-index: 10000;">';
    h += '<div style="width: ' + (cw) + 'px; height: ' + (ch - 35) + 'px; background: #000; opacity: 0.2; position: fixed; top: 35px; left: 0; z-index: 10000;"></div>';
    h += '<div style="padding: 10px 20px; width: ' + (cw * 0.5) + 'px; text-align: center; background: #000; color: #FFF; border-radius: 5px; position: fixed; bottom: 40%; left: ' + ((cw * 0.5 - 40) / 2) + 'px; z-index: 10000;">'+msg+'</div>';
    h += '</div>';
    h += '<script>setTimeout(function(){$(\'#msgPop\').html(\'\');},2000)</script>';
    $('#msgPop').html(h);
}


//小程序弹窗
function xcxPop(){
    var cw = document.documentElement.clientWidth;
    var ch = document.documentElement.clientHeight;
    var h = '';
    h += '<div style="position: fixed; top: 0; left: 0; z-index: 10000;">';
    h += '<div style="width: ' + (cw) + 'px; height: ' + (ch - 35) + 'px; background: #000; opacity: 0.2; position: fixed; top: 35px; left: 0; z-index: 10000;" onclick="$(\'#xcxPop\').html(\'\');"></div>';
    h += '<div style="padding: 10px 0; width: ' + (cw * 0.8) + 'px; height: 85vh; text-align: center; background: #FFF; color: #555; border-radius: 5px; overflow: auto; position: fixed; top: 10%; left: ' + ((cw * 0.2) / 2) + 'px; z-index: 10000;">';
    h += '<div><b>进入小程序，更多操作</b></div>';
    h += '<div style="width: ' + (cw * 0.8) + 'px; text-align: center;">';
    //h += '<img src="imgs/gh_7c8752949ae9_1280.jpg" style="width: 60%;"/>';
    h += '<img src="imgs/xcxma.jpg" style="width: 60%;"/>';
    h += '<div style="font-size: 12px;">请长按上面二维码，在出现的菜单中，<br/>选择“识别图中的二维码”：</div>';
    h += '<img src="imgs/xcx008.png" style="width: 60%; border: 1px solid #0088cc;"/>';
    h += '</div>';
    h += '</div>';
    h += '</div>';
    $('#xcxPop').html(h);
}


//获取地址栏中参数
function getParamByUrl(name){
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r==null) return '';
    return  unescape(r[2]);
}


//生成随机数
function randInt(min, max) {
    // 加1是因为我们想要包含max值在内
    return Math.floor(Math.random() * (max - min + 1)) + min;
}


//获取登录信息
function getUserInfo(){
    var cache = window.localStorage.getItem(userLogin);
    if (!cache) { return ''; }
    return JSON.parse(cache);
}


//设置登录信息
function setUserInfo(e){
    window.localStorage.setItem(userLogin, JSON.stringify(e.val));
}


//获取缓存
function getCache(key){
    var cache = window.localStorage.getItem(key);
    if (!cache) { return ''; }
    return JSON.parse(cache);
}


//设置缓存
function setCache(e){
    window.localStorage.setItem(e.key, JSON.stringify(e.val));
}